package net.skyedu.service;

import java.io.IOException;
import java.io.PrintWriter;
import java.net.URLDecoder;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.skyedu.bean.SysCourse;
import net.skyedu.dao.DaoSupport;

public class UpCourse extends HttpServlet {

	private static final long serialVersionUID = 1L;

	public UpCourse() {
		super();
	}

	public void destroy() {
		super.destroy(); // Just puts "destroy" string in log
	}

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		response.setContentType("text/html;charset=utf-8");
		doPost(request,response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/html;charset=utf-8");
		String Id = request.getParameter("id");
		String year = request.getParameter("year");
		String term = request.getParameter("term");
			term=URLDecoder.decode(term,"UTF-8");
		String graname = request.getParameter("graname");
			graname=URLDecoder.decode(graname,"UTF-8");
		String subject = request.getParameter("subject");
			subject=URLDecoder.decode(subject,"UTF-8");
		String claType = request.getParameter("claType");
			claType=URLDecoder.decode(claType,"UTF-8");
		String claLevel = request.getParameter("claLevel");
			claLevel=URLDecoder.decode(claLevel,"UTF-8");
		String beginTime = request.getParameter("beginTime");
		String endTime = request.getParameter("endTime");
		if(beginTime != null && !"".equals(beginTime)){
			beginTime=URLDecoder.decode(beginTime,"UTF-8");
		}
		if(endTime != null && !"".equals(endTime)){
			endTime=URLDecoder.decode(endTime,"UTF-8");
		}
		//单课次费用
		String perunitFee = request.getParameter("perunitFee");
		String predictNum = request.getParameter("predictNum");
		String claNum = request.getParameter("claNum");
		String claHour = request.getParameter("claHour");
		String bookFee = request.getParameter("bookFee");
		String bookVersion = request.getParameter("bookVersion");
		if(bookVersion != null && !"".equals(bookVersion)){
			bookVersion=URLDecoder.decode(bookVersion,"UTF-8");
		}
		String claTime = request.getParameter("claTime");
//		String claContent = request.getParameter("claContent");
//		if(claContent != null && !"".equals(claContent)){
//			claContent=URLDecoder.decode(claContent,"UTF-8");
//		}
//		String teaAims = request.getParameter("teaAims");
//		if(teaAims != null && !"".equals(teaAims)){
//			teaAims=URLDecoder.decode(teaAims,"UTF-8");
//		}
//		String knowledge = request.getParameter("knowledge");
//		if(knowledge != null && !"".equals(knowledge)){
//			knowledge=URLDecoder.decode(knowledge,"UTF-8");
//		}
//		String difficulty = request.getParameter("difficulty"); //难易程度
		DaoSupport ds = new DaoSupport();
		SysCourse sc = new SysCourse();
		sc.setCouId(Integer.parseInt(Id));
		sc.setYear(year);
		sc.setTerName(term);
		sc.setSubName(subject);
		sc.setGraName(graname);
		sc.setClaType(claType);
		sc.setClaLevel(claLevel);
		sc.setBeginTime(beginTime);
		sc.setEndTime(endTime);
		sc.setClaNumber(Integer.parseInt(claNum));
		sc.setClaHour(Double.parseDouble(claHour));
		sc.setPerunitFee(Integer.parseInt(perunitFee));
		sc.setPredictNum(Integer.parseInt(predictNum));
		sc.setBookFee(Double.parseDouble(bookFee));
		sc.setBookVersion(bookVersion);
		sc.setClassTime(Float.parseFloat(claTime));
		
		int num = ds.upCourse(sc);
		
		boolean flag = false;
		if(num > 0){
			flag = true;
		}
		 PrintWriter out = response.getWriter();
		 out.print(flag);
		 out.flush();
		 out.close();
	}

	public void init() throws ServletException {}

}
